package com.example.fmgidsprototype.webservice;

import java.util.ArrayList;

import com.example.fmgidsprototype.webservice.n_cst_adapter_account;
import android.os.Bundle;
import android.accounts.Account;
import android.app.ListActivity;
import android.content.Intent;
import android.view.View;
import android.widget.ListView;

public class AccountList extends ListActivity {
	public static final int REQUEST_CODE = 1;
	public static final String INTENT_ARGUMENT = "accounts";
	public static final String RETURN_EMAIL = "email";
			
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_account_list);
		
		Bundle lnv_data =	this.getIntent().getExtras();
		
		if (lnv_data == null)
		{
			return;
		}
		else
		{
			Object[] lnv_return = (Object[]) lnv_data.getParcelableArray(INTENT_ARGUMENT);
			ArrayList<Account> lnv_list = new ArrayList<Account>();
						
			for(int li_loop = 0; li_loop < lnv_return.length; li_loop++)
			{
				lnv_list.add((Account) lnv_return[li_loop]);
			}
			
			Account[] lnv_accounts = (Account[]) lnv_list.toArray(new Account[lnv_list.size()]);
			
			n_cst_adapter_account lnv_adapter = new n_cst_adapter_account(this, lnv_accounts);
			this.setListAdapter(lnv_adapter);
		}	
	}
	/**
	@Override
	protected void onDestroy() 
	{
		super.onDestroy();
		n_cst_common.of_set_user_name(this, "n/a");
	}
	*/
	@Override        
	protected void onListItemClick(ListView l, View v, int position, long id)
	{
		Account lnv_account = (Account)this.getListView().getItemAtPosition(position);
		
		Intent luo_data = new Intent();
		
		luo_data.putExtra(RETURN_EMAIL, lnv_account.name);
		// Activity finished ok, return the data
		setResult(RESULT_OK, luo_data);
		
		finish();

	}
/*
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_account_list, menu);
		return true;
	}
*/
}
